# import heapq
#
# heap = []
# heapq.heappush(heap, 3)
# heapq.heappush(heap, 2)
# heapq.heappush(heap, 1)
# print(heap)  # 输出为 [1, 3, 2]
#
# # 要想有序输出 堆的元素
# heapq.heappop(heap) # 输出1
# heapq.heappop(heap) # 输出2
# heapq.heappop(heap) # 输出3
#
# # 要想输出前n个最大值，前n个最小值，可以使用
# heapq.nlargest(n, heap)
# heapq.nsmallest(n, heap)
#


from heapq import *


def heap_sort(iterable):
    h = []
    for value in iterable:
        heappush(h, value)
    return [heappop(h) for _ in range(len(h))]


if __name__ == '__main__':
    print(heap_sort([1, 3, 5, 9, 2, 123, 4, 88]))
